<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		
	<span class="different-posts different-posts_earlier">📖 <a href="/page/39">earlier posts</a> 📖</span>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/9. DNS服务器(三)：子域授权及转发/">DNS服务器(三)：子域授权及转发</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<h2 id="一、DNS服务器子域授权的实现"><a href="#一、DNS服务器子域授权的实现" class="headerlink" title="一、DNS服务器子域授权的实现"></a>一、DNS服务器子域授权的实现</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;通常自己架设DNS服务器给自己使用的公司都是内部有特殊需求，或者公司内部域名较多，为了方便以后的管理而架设。我们知道一个域名就是一个区域，一般每个区域都会有专人负责管理，当一个公司人员足够多时，这时就会有划分子域给下级部门管理的需求。在一个区域下划分子域，并给子域指定一个新的DNS服务器，这种方法是可以实现的，我们通常称这种划分子区域的方法为子域授权。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;实例：给wubinary.com域名划分一个blog.wubinary.com的子域。bind的安装配置及主DNS服务器的架设不再此讨论</p>
<ol>
<li>首先架设一个主DNS服务器，编辑/var/named/wubinary.com.zone文件，主DNS服务器的IP为192.168.0.6，资源记录数据文件如下：</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="variable">$TTL</span> 600</div><div class="line">@ IN SOA dns.wubinary.com. dnsadmin.wubinary.com. (</div><div class="line"> 2014031203</div><div class="line"> 2H</div><div class="line"> 4M</div><div class="line"> 1D</div><div class="line"> 2D )</div><div class="line">@ IN NS dns.wubinary.com.</div><div class="line">@ IN NS ns2.wubinary.com.</div><div class="line">@ IN MX 10 mail.wubinary.com.</div><div class="line">dns IN A 192.168.0.6</div><div class="line">mail IN A 192.168.0.12</div><div class="line">www IN A 192.168.0.48</div><div class="line">ns2 IN A 192.168.0.80</div><div class="line">blog.wubinary.com. IN NS dns.blog.wubinary.com.</div><div class="line">dns.blog.wubinary.com. IN A 192.168.0.2</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意，以上最后两行为子域的DNS服务器，只要在主DNS服务器定义好了子域的DNS服务器就等于给子域授权了。</p>
<ol>
<li>然后在回到子域的服务器，192.168.0.2上配置子域区域。打开/etc/named.rfc1912.zones文件，在最末尾定义子域的区域。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">zone <span class="string">"blog.wubinary.com"</span> IN &#123;</div><div class="line"> <span class="built_in">type</span> master;</div><div class="line"> file <span class="string">"blog.wubinary.com.zone"</span>;</div><div class="line">&#125;;</div></pre></td></tr></table></figure>
<ol>
<li>接着再定义子域DNS服务器的资源记录文件，/var/named/blog.wubinary.com.zone。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="variable">$TTL</span> 600</div><div class="line">@ IN SOA dns.blog.wubinary.com. dnsadmin.blog.wubinary.com. (</div><div class="line"> 2014031201</div><div class="line"> 1H</div><div class="line"> 5M</div><div class="line"> 3D</div><div class="line"> 1D )</div><div class="line">@ IN NS dns.blog.wubinary.com.</div><div class="line">dns IN A 192.168.0.2</div><div class="line">www IN A 192.168.0.78</div><div class="line">ftp IN A 192.168.0.23</div></pre></td></tr></table></figure>
<ol>
<li>重新启动两边的DNS服务，测试一下子域授权是否成功。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;主域机器测试：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%B8%89" alt=""></figure>%EF%BC%9A%E5%AD%90%E5%9F%9F%E6%8E%88%E6%9D%83%E5%8F%8A%E8%BD%AC%E5%8F%91/01.jpeg?raw=true)</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%B8%89" alt=""></figure>%EF%BC%9A%E5%AD%90%E5%9F%9F%E6%8E%88%E6%9D%83%E5%8F%8A%E8%BD%AC%E5%8F%91/02.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;子域机器测试：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%B8%89" alt=""></figure>%EF%BC%9A%E5%AD%90%E5%9F%9F%E6%8E%88%E6%9D%83%E5%8F%8A%E8%BD%AC%E5%8F%91/03.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试正常，操作成功！</p>
<h2 id="二、DNS服务器域名解析转发"><a href="#二、DNS服务器域名解析转发" class="headerlink" title="二、DNS服务器域名解析转发"></a>二、DNS服务器域名解析转发</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS转发的意义在于，定向查询，一台DNS服务器在获取到查询请求时，自己不尝试解析域名，而转发查询请求给指定的DNS服务器实现此次解析操作。假设，我们现在碰到这么一种情况，我们的DNS服务器是处在一个内网的网段，与外网不能直接通信，在这个局域网中唯一一个能和外网通信的是路由器或者其它的DNS服务器。那么如果我们想要实现通过这台局域网的DNS服务器查询解析外网的域名，就要用到转发的功能了。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;转发可以用参数forwarders和forward实现：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">forwarders &#123; IP_ADDR1; IP_ADDR; ...&#125;;</div><div class="line">forward &#123; only|first &#125;;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;参数说明：</p>
<ul>
<li>forwarders：用于定义转发的服务器的IP地址，可以写多个，用分号隔开。</li>
<li>forward：用于定义转发的操作，only为只作转发操作，有结果则返回结果，没有结果则什么操作也不作；first为先作转发操作，如果没有结果则去递归查找。</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;全局和区域：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这两个参数可以放在全局定义，也可放在区域定义，也可以两个同时使用，但不管怎样，放在区域的优先权更高。如果用于特定区域则把转发定义在区域内，如果用于全局，则把转发定义在全局。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;转发实例：让上面的区域wubinary.com可以实现解析外网的域名。</p>
<ol>
<li>区域wubinary.com所设的DNS服务器为局域网的IP地址，不可以解析外网域名。</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%B8%89" alt=""></figure>%EF%BC%9A%E5%AD%90%E5%9F%9F%E6%8E%88%E6%9D%83%E5%8F%8A%E8%BD%AC%E5%8F%91/04.jpeg?raw=true)</p>
<ol>
<li>由上图可以看出wubinary.com区域不能解析51cto.com的NS记录，我们添加一个转发功能。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑/etc/named.conf文件，添加转发ip 192.168.0.1</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%B8%89" alt=""></figure>%EF%BC%9A%E5%AD%90%E5%9F%9F%E6%8E%88%E6%9D%83%E5%8F%8A%E8%BD%AC%E5%8F%91/05.jpeg?raw=true)</p>
<ol>
<li>修改完成后，重启服务，测试一下，可以解析了，转发成功！</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%B8%89" alt=""></figure>%EF%BC%9A%E5%AD%90%E5%9F%9F%E6%8E%88%E6%9D%83%E5%8F%8A%E8%BD%AC%E5%8F%91/06.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：有的时候，如果我们事先已经知道了某个区域DNS服务器的地址，为了不让当前DNS服务器向根查询结果，那么我们就可以直接使用转发，向当前DNS服务器指定一个地址，让它查询直接向这个地址请求，这样做的好处能明显的提高响应速度。</p>
<h2 id="三、DNS中的访问控制列表"><a href="#三、DNS中的访问控制列表" class="headerlink" title="三、DNS中的访问控制列表"></a>三、DNS中的访问控制列表</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有的时候我们须要在DNS配置文件中指定n个IP地址，如果全都写在一起的话，每块地方都要写一次，那么相当麻烦，如果使用一个参数定义那一片的IP地址，那么管理起来就相当方便了，这个就是DNS中的ACL,bind支持的访问控制表。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;格式：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"> acl ACL_NAME &#123;</div><div class="line"> 172.16.0.0/16;</div><div class="line"> 192.168.0.0/24</div><div class="line"> 127.0.0.0/8;</div><div class="line"> ...</div><div class="line"> ...</div><div class="line">&#125;;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在全局选项中定义ACL，给每个ACL取一个名字，这样以后每次引用，只须在填定IP地址的地方填写那个变量就行了。在bind中有几个事先定义好的ACL:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">any: 任何主机</div><div class="line">none: 无一主机</div><div class="line"><span class="built_in">local</span>: 本机</div><div class="line">localnet: 本机的所在的网络</div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/7. DNS服务器(一)：基本原理/">DNS服务器(一)：基本原理</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<h2 id="一、简介"><a href="#一、简介" class="headerlink" title="一、简介"></a>一、简介</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;网络中的主机通信是通过IP地址来实现的，通常IPv4的地址是四个数字加点组成，如果和每台主机通信我们都要去记忆IP地址的话，这通常对于人类来讲是相当痛苦的。于是网络上就有了一套为了解决这个问题的方案出现了，也就是DNS主机名称解析系统。它是一套能够将数以千万计的IP地址通过查询DNS数据库，轻松的转化成与之对应的一串单词字符串，也就是主机名，网络上称之为域名，相对于IP地址，用单词组成的域名明显好记多了。</p>
<h2 id="二、DNS域名解析系统的层级关系"><a href="#二、DNS域名解析系统的层级关系" class="headerlink" title="二、DNS域名解析系统的层级关系"></a>二、DNS域名解析系统的层级关系</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS域名解析系统是有层级关系的，整个层级关系的表现形式就像一棵大树，每一层，我们称之为域。最顶层的域我们通常叫作根域，用点号表示，第二层通常用com、net、edu、gov、mil、org….，这层我们叫作顶级域，往下第三层，也就是我们经常见到的域名了，如,51cto.com，这一层我们称之为二级域，当二级域加上www后，就是第四层了，就这样一直往下细分。域名的写法通常是由小到大，从左往右书写，用点连接，最后加点表示根，整个结构如下图所示：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%B8%80" alt=""></figure>%EF%BC%9A%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86/01.jpeg?raw=true)</p>
<h2 id="三、DNS的资源记录"><a href="#三、DNS的资源记录" class="headerlink" title="三、DNS的资源记录"></a>三、DNS的资源记录</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;我们要查询这些庞大数据当然要有专门的主机负责这些工作了，提供查询、存储DNS数据服务的主机我们称之为DNS服务器。网络上为了方便域名的注册、管理、解析，将DNS域名映射到特定类型的资源信息，我们称之为资源记录。资源记录是有类型的，</p>
<h3 id="资源记录类型"><a href="#资源记录类型" class="headerlink" title="资源记录类型"></a>资源记录类型</h3><table>
<thead>
<tr>
<th style="text-align:center">SOA</th>
<th style="text-align:center">NS</th>
<th style="text-align:center">MX</th>
<th style="text-align:center">A</th>
<th style="text-align:center">PTR</th>
<th style="text-align:center">AAAA</th>
<th style="text-align:center">CNAME</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">起始授权</td>
<td style="text-align:center">域名服务器</td>
<td style="text-align:center">邮件交换器</td>
<td style="text-align:center">域名–&gt;IP</td>
<td style="text-align:center">IP–&gt;域名</td>
<td style="text-align:center">域名–&gt;IPv6</td>
<td style="text-align:center">别名记录</td>
</tr>
<tr>
<td style="text-align:center">特点：只能有一个，而且必须是第一个</td>
<td style="text-align:center">特点：用于表示DNS服务器的域名地址</td>
<td style="text-align:center">特点：用于一个域下的邮件使用</td>
<td style="text-align:center">特点：我们经常用到的就是它了</td>
<td style="text-align:center">特点：和A记录相反，用于反向解析</td>
<td style="text-align:center">特点：基本不用</td>
<td style="text-align:center">特点：用于作A记录的域名的别名，</td>
</tr>
</tbody>
</table>
<h2 id="四、DNS服务器的工作原理"><a href="#四、DNS服务器的工作原理" class="headerlink" title="四、DNS服务器的工作原理"></a>四、DNS服务器的工作原理</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;假设我们以wubinary.blog.51cto.com为例：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第一步：当我们使用DNS客户端请求查询此域名的的A记录时，DNS服务器首先会判断所要查询域名是属于哪个区域，是否在自己的管辖范围，假设此次域名不在管辖范围。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第二步：为了确定当前域名是在哪个级别，DNS服务器要向根询求帮助，根会向DNS服务器返回所在域名的顶级域的DNS服务器地址，也就是根的下一级com的DNS服务器地址。此时DNS服器根据这个地址又再次查询，此次查询获得了51cto.com的DNS的服务器地址。于是终于确定了wubinary.blog.51cto.com的区域所在的DNS服务器地址了。DNS服务器的此类确定一个地址，并使用这个址去查询下一个的查询方式我们称之为<strong>迭代查询</strong>。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第三步：确定了区域地址后，51cto.com为了向DNS服务器返回结果需要一级一级的往下查。一开始查询到了blog.51cto.com的DNS服务器地址，于是blog.51cto.com的DNS服务器则向下查询。blog.51cto.com又查询到了wubinary.blog.51cto.com的DNS服务器地址，此时的地址正是DNS服务器要找的地址。到了这一步，wubinary.blog.51cto.com的DNS服务器则会把结果向它的上级汇报，于是上一级又向上一级汇报，最终结果回到了最初的DNS服务器，此时DNS客户端才能获得最终的IP地址。像这样DNS服务器的数据逐级遍历及逐级返回的过程，我们称之为<strong>递归查询</strong>。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果我们查询的域名正好和当前查询使用的DNS服务器所匹配，则DNS服务器会先查询本地缓存是否存在，如果存在则返回缓存数据，如果不存在则去数据文件中读取数据并运回结果。</p>
<h2 id="五、三个与解析有关的配置文件"><a href="#五、三个与解析有关的配置文件" class="headerlink" title="五、三个与解析有关的配置文件"></a>五、三个与解析有关的配置文件</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/etc/hosts：此文件早期在没有出现DNS服务器的时候，作用和DNS服务器类似，不过随着网络的发展，单个文件根本无法满足需求，于是，此文件通常运用于本地IP解析。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/etc/resolv.conf：定义DNS服务器IP地址，本地解析域名通常使用的都是这里面定义的IP地址。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;/etc/nsswitch.conf：这个文件则是来决定先要使用/etc/hosts还是/etc/resolv.conf的设置。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;总结：理解DNS的树状结构、递归及迭代查询后，其它就好办了。</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/5. centos安装配置dnsmasq/">centos安装配置dnsmasq</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;公司业务使用的mydns搭建dns服务器（参考<a href="https://hcldirgit.github.io/2017/08/05/4.%20mydns%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/" target="_blank" rel="external">mydns安装配置</a>），使用mydns的优点是配置、更改容易，能实现自动增加记录，而缺点也是显而易见的，因为mydns使用mysql作为数据存储仓库，如果查询很频繁的话，就会影响效率，甚至导致服务中止。但这个缺点也不是不可克服，只要在前端多配置几台dns缓存服务器即可。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在centos上使用dnsmasq是不错的选择，安装简易，配置更容易。</p>
<ol>
<li>安装</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y dnsmasq</div></pre></td></tr></table></figure>
<ol>
<li>配置</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;假如mydns服务器为 1.1.1.1</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim  /etc/dnsmasq.conf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;增加一行：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">resolv-file=/etc/resolv_dnsmasq.conf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存,然后编辑 /etc/resolv_dnsmasq.conf</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;增加一行 </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">nameserver 1.1.1.1</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存该文件，启动dnsmasq</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/etc/init.d/dnsmasq  start</div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/6. 递归查询和迭代查询的区别/">递归查询和迭代查询的区别</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<h2 id="递归查询"><a href="#递归查询" class="headerlink" title="递归查询"></a>递归查询</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;递归查询是一种DNS 服务器的查询模式，在该模式下DNS 服务器接收到客户机请求，必须使用一个准确的查询结果回复客户机。如果DNS 服务器本地没有存储查询DNS 信息，那么该服务器会询问其他服务器，并将返回的查询结果提交给客户机。</p>
<h2 id="迭代查询"><a href="#迭代查询" class="headerlink" title="迭代查询"></a>迭代查询</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS 服务器另外一种查询方式为迭代查询，DNS 服务器会向客户机提供其他能够解析查询请求的DNS 服务器地址，当客户机发送查询请求时，DNS 服务器并不直接回复查询结果，而是告诉客户机另一台DNS 服务器地址，客户机再向这台DNS 服务器提交请求，依次循环直到返回查询的结果<br>为止。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;两种过程的示意图：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/%E9%80%92%E5%BD%92%E6%9F%A5%E8%AF%A2%E5%92%8C%E8%BF%AD%E4%BB%A3%E6%9F%A5%E8%AF%A2%E7%9A%84%E5%8C%BA%E5%88%AB/01.gif?raw=true" alt=""></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/4. mydns安装配置/">mydns安装配置</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="http://mydns.bboy.net/download/mydns-1.1.0.tar.gz" target="_blank" rel="external">远程下载</a></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="http://www.apelearn.com/bbs/data/attachment/forum/month_1002/mydns-mysql-1.1.0-1.i386.rpm" target="_blank" rel="external">rpm包下载</a></p>
<h2 id="1-因为mydns依赖mysql，所以需要先安装mysql。"><a href="#1-因为mydns依赖mysql，所以需要先安装mysql。" class="headerlink" title="1.因为mydns依赖mysql，所以需要先安装mysql。"></a>1.因为mydns依赖mysql，所以需要先安装mysql。</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y mysql-server</div></pre></td></tr></table></figure>
<h2 id="2-安装mydns"><a href="#2-安装mydns" class="headerlink" title="2 安装mydns"></a>2 安装mydns</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">wget  http://www.lishiming.net/data//a ... ql-1.1.0-1.i386.rpm</div><div class="line">rpm -ivh mydns-mysql-1.1.0-1.i386.rpm</div></pre></td></tr></table></figure>
<h2 id="3-创建库和表"><a href="#3-创建库和表" class="headerlink" title="3.创建库和表"></a>3.创建库和表</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">mysql -uroot  -e <span class="string">"create database mydns"</span></div><div class="line">mysql -uroot mydns</div><div class="line">mysql&gt; CREATE TABLE `soa` (   `id` int(10) unsigned NOT NULL auto_increment,   `origin` char(255) default NULL,   `ns` char(255) default NULL,   `mbox` char(255) default NULL,   `serial` int(10) unsigned default <span class="string">'1'</span>,   `refresh` int(10) unsigned default <span class="string">'28800'</span>,   `retry` int(10) unsigned default <span class="string">'7200'</span>,   `expire` int(10) unsigned default <span class="string">'604800'</span>,   `minimum` int(10) unsigned default <span class="string">'86400'</span>,   `ttl` int(10) unsigned default <span class="string">'86400'</span>,   `xfer` char(255) default NULL,   PRIMARY KEY  (`id`),   UNIQUE KEY `origin` (`origin`) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=gbk;</div><div class="line"></div><div class="line">mysql&gt;  CREATE TABLE `rr` (   `id` int(10) unsigned NOT NULL auto_increment,   `zone` int(10) unsigned NOT NULL,   `name` char(64) default NULL,   `<span class="built_in">type</span>` enum(<span class="string">'A'</span>,<span class="string">'AAAA'</span>,<span class="string">'CNAME'</span>,<span class="string">'HINFO'</span>,<span class="string">'MX'</span>,<span class="string">'NAPTR'</span>,<span class="string">'NS'</span>,<span class="string">'PTR'</span>,<span class="string">'RP'</span>,<span class="string">'SRV'</span>,<span class="string">'TXT'</span>) default NULL,   `data` char(128) default NULL,   `aux` int(10) unsigned NOT NULL,   `ttl` int(10) unsigned NOT NULL default <span class="string">'600'</span>,   `inter` tinyint(3) unsigned NOT NULL default <span class="string">'1'</span>,   `intra` tinyint(3) unsigned NOT NULL default <span class="string">'1'</span>,   PRIMARY KEY  (`id`),   KEY `name` (`name`),   KEY `rr` (`zone`,`name`,`<span class="built_in">type</span>`,`data`) ) ENGINE=MyISAM AUTO_INCREMENT=1437896 DEFAULT CHARSET=gbk;</div></pre></td></tr></table></figure>
<h2 id="4-创建第一个zone"><a href="#4-创建第一个zone" class="headerlink" title="4.创建第一个zone"></a>4.创建第一个zone</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">mysql&gt; use mydns</div><div class="line">mysql&gt; insert into soa (id, origin,ns,mbox,serial,refresh,retry,expire,minimum,ttl) values(1,<span class="string">'abc.com.'</span>, <span class="string">'ns.abc.com.'</span>,  <span class="string">'root.aminglinux.com'</span>, 1, 28800, 7200, 604800, 86400, 86400);</div><div class="line">mysql&gt; insert into rr values(1, 1, <span class="string">'www'</span>, <span class="string">'A'</span>, <span class="string">'1.1.1.1'</span>, 0, 1, 1, 1, 1);</div></pre></td></tr></table></figure>
<h2 id="5-配置"><a href="#5-配置" class="headerlink" title="5.配置"></a>5.配置</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show create table soa\G;</div><div class="line"></div><div class="line"></div><div class="line">CREATE TABLE `soa` (   `id` int(10) unsigned NOT NULL auto_increment,   `origin` char(255) default NULL,   `ns` char(255) default NULL,   `mbox` char(255) default NULL,   `serial` int(10) unsigned default <span class="string">'1'</span>,   `refresh` int(10) unsigned default <span class="string">'28800'</span>,   `retry` int(10) unsigned default <span class="string">'7200'</span>,   `expire` int(10) unsigned default <span class="string">'604800'</span>,   `minimum` int(10) unsigned default <span class="string">'86400'</span>,   `ttl` int(10) unsigned default <span class="string">'86400'</span>,   `xfer` char(255) default NULL,   PRIMARY KEY  (`id`),   UNIQUE KEY `origin` (`origin`) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=gbk;</div><div class="line"></div><div class="line">mysql&gt; show create table rr\G;</div><div class="line">*************************** 1. row ***************************</div><div class="line">       Table: rr</div><div class="line">CREATE TABLE `rr` (   `id` int(10) unsigned NOT NULL auto_increment,   `zone` int(10) unsigned NOT NULL,   `name` char(64) default NULL,   `<span class="built_in">type</span>` enum(<span class="string">'A'</span>,<span class="string">'AAAA'</span>,<span class="string">'CNAME'</span>,<span class="string">'HINFO'</span>,<span class="string">'MX'</span>,<span class="string">'NAPTR'</span>,<span class="string">'NS'</span>,<span class="string">'PTR'</span>,<span class="string">'RP'</span>,<span class="string">'SRV'</span>,<span class="string">'TXT'</span>) default NULL,   `data` char(128) default NULL,   `aux` int(10) unsigned NOT NULL,   `ttl` int(10) unsigned NOT NULL default <span class="string">'600'</span>,   `inter` tinyint(3) unsigned NOT NULL default <span class="string">'1'</span>,   `intra` tinyint(3) unsigned NOT NULL default <span class="string">'1'</span>,   PRIMARY KEY  (`id`),   KEY `name` (`name`),   KEY `rr` (`zone`,`name`,`<span class="built_in">type</span>`,`data`) ) ENGINE=MyISAM AUTO_INCREMENT=1437896 DEFAULT CHARSET=gbk;</div><div class="line"></div><div class="line">mysql&gt; select * from soa <span class="built_in">where</span> id=3;</div><div class="line">+----+--------------+--------------+---------------------+--------+---------+-------+--------+---------+-------+------+</div><div class="line">| id | origin       | ns           | mbox                | serial | refresh | retry | expire | minimum | ttl   | xfer |</div><div class="line">+----+--------------+--------------+---------------------+--------+---------+-------+--------+---------+-------+------+</div><div class="line">|  3 | example.com. | ns.example.com. | julyclyde.gmail.com |      1 |   28800 |  7200 | 604800 |   86400 | 86400 | NULL |</div><div class="line"></div><div class="line">mysql&gt; select * from rr <span class="built_in">where</span> id=1;</div><div class="line">+----+------+------+------+----------------+-----+-----+-------+-------+</div><div class="line">| id | zone | name | <span class="built_in">type</span> | data           | aux | ttl | inter | intra |</div><div class="line">+----+------+------+------+----------------+-----+-----+-------+-------+</div><div class="line">|  1 |    1 | www  | A    | 1.1.1.1 |   0 |   1 |     1 |     1 |</div><div class="line"></div><div class="line">cat  /etc/mydns.conf</div><div class="line"></div><div class="line"><span class="comment">##</span></div><div class="line"><span class="comment">##  /etc/mydns.conf</span></div><div class="line"><span class="comment">##  Wed Nov 19 10:04:14 2008</span></div><div class="line"><span class="comment">##  For more information, see mydns.conf(5).</span></div><div class="line"><span class="comment">##</span></div><div class="line"></div><div class="line"></div><div class="line">                                <span class="comment"># DATABASE INFORMATION</span></div><div class="line"></div><div class="line">db-host = localhost             <span class="comment"># SQL server hostname</span></div><div class="line">db-user = yourdbname                 <span class="comment"># SQL server username</span></div><div class="line">db-password = yourpassword          <span class="comment"># SQL server password</span></div><div class="line">database = dns                  <span class="comment"># MyDNS database name</span></div><div class="line"></div><div class="line"></div><div class="line">                                <span class="comment"># GENERAL OPTIONS</span></div><div class="line"></div><div class="line">user = nobody                   <span class="comment"># Run with the permissions of this user</span></div><div class="line">group = nobody                  <span class="comment"># Run with the permissions of this group</span></div><div class="line">listen = *                         <span class="comment"># Listen on these addresses ('*' for all)</span></div><div class="line">no-listen =                     <span class="comment"># Do not listen on these addresses</span></div><div class="line"></div><div class="line"></div><div class="line">                                <span class="comment"># CACHE OPTIONS</span></div><div class="line"></div><div class="line">zone-cache-size = 1024          <span class="comment"># Maximum number of elements stored in the zone cache</span></div><div class="line">zone-cache-expire = 60          <span class="comment"># Number of seconds after which cached zones expires</span></div><div class="line">reply-cache-size = 1024         <span class="comment"># Maximum number of elements stored in the reply cache</span></div><div class="line">reply-cache-expire = 30         <span class="comment"># Number of seconds after which cached replies expire</span></div><div class="line"></div><div class="line"></div><div class="line">                                <span class="comment"># ESOTERICA</span></div><div class="line"></div><div class="line"><span class="built_in">log</span> = /var/<span class="built_in">log</span>/mydns.log                <span class="comment"># Facility to use for program output (LOG_*/stdout/stderr)</span></div><div class="line">pidfile = /var/run/mydns.pid    <span class="comment"># Path to PID file</span></div><div class="line">timeout = 120                   <span class="comment"># Number of seconds after which queries time out</span></div><div class="line">multicpu = 4                    <span class="comment"># Number of CPUs installed on your system - (deprecated)</span></div><div class="line">servers = 2                     <span class="comment"># Number of servers to run</span></div><div class="line">recursive = 8.8.8.8                     <span class="comment"># Location of recursive resolver</span></div><div class="line">recursive-timeout =             <span class="comment"># Number of seconds before first retry</span></div><div class="line">recursive-retries =             <span class="comment"># Number of retries before abandoning recursion</span></div><div class="line">recursive-algorithm =           <span class="comment"># Recursion retry algorithm one of: linear, exponential, progressive</span></div><div class="line">allow-axfr = no                 <span class="comment"># Should AXFR be enabled?</span></div><div class="line">allow-tcp = no                  <span class="comment"># Should TCP be enabled?</span></div><div class="line">allow-update = no               <span class="comment"># Should DNS UPDATE be enabled?</span></div><div class="line">ignore-minimum = no             <span class="comment"># Ignore minimum TTL for zone?</span></div><div class="line">soa-table = soa                 <span class="comment"># Name of table containing SOA records</span></div><div class="line">rr-table = rr                   <span class="comment"># Name of table containing RR data</span></div><div class="line">use-soa-active = no             <span class="comment"># Use the soa active attribute if provided</span></div><div class="line">use-rr-active = no              <span class="comment"># Use the rr active attribute if provided</span></div><div class="line">notify-enabled = no             <span class="comment"># Enable notify from updates</span></div><div class="line">notify-source = 0.0.0.0         <span class="comment"># Source address for ipv4 notify messages</span></div><div class="line">notify-source6 = 0.0.0.0        <span class="comment"># Source address for ipv6 notify messages</span></div><div class="line">notify-timeout = 60             <span class="comment"># Number of seconds before first retry</span></div><div class="line">notify-retries = 5              <span class="comment"># Number of retries before abandoning notify</span></div><div class="line">notify-algorithm = linear       <span class="comment"># Notify retry algorithm one of: linear, exponential, progressive</span></div><div class="line">ixfr-enabled = no               <span class="comment"># Enable IXFR functionality</span></div><div class="line">ixfr-gc-enabled = no            <span class="comment"># Enable IXFR GC functionality</span></div><div class="line">ixfr-gc-interval = 86400        <span class="comment"># How often to run GC for IXFR</span></div><div class="line">ixfr-gc-delay = 600             <span class="comment"># Delay until first IXFR GC runs</span></div><div class="line">extended-data-support = no      <span class="comment"># Support extended data fields for large TXT records</span></div><div class="line">dbengine = MyISAM               <span class="comment"># Support different database engines</span></div><div class="line">wildcard-recursion = 0          <span class="comment"># Wildcard ancestor search levels</span></div><div class="line">soa-where =                     <span class="comment"># Extra WHERE clause for SOA queries</span></div><div class="line">rr-where =    inter=1                   <span class="comment"># Extra WHERE clause for RR queries</span></div></pre></td></tr></table></figure>
<h2 id="6-启动"><a href="#6-启动" class="headerlink" title="6.启动"></a>6.启动</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/etc/init.d/mydns start</div></pre></td></tr></table></figure>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/2. DNS介绍/">DNS介绍</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS 为 Domain Name System （域名系统）的缩写，它是一种将 ip 地址转换成对应的主机名或将主机名转换成与之相对应 ip 的一种服务机制。其中通过域名解析出 ip 地址的叫做正向解析，通过 ip 地址解析出域名的叫做反向解析。 DNS 使用 TCP 和 UDP ，端口号都是53，但它主要使用 UDP ，服务器之间备份使用 TCP 。全世界只有 13 台 “根”服务器，1 个根服务器放在美国，其他 12 台为辅根服务器，DNS 服务器根据角色可以分为：主 DNS 、从 DNS 、缓存 DNS 服务器，DNS 转发服务器。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先来看看域名的结构组成，平时访问网站的时候，都会用一个域名去请求，比如 www.baidu.com ，其实在 com 后面还有一个点，这个点叫做根域。下图是一个域名的树状结构，根域下面会有 .com  .cn  .net 等顶级域，在顶级域下面又有了第二层域，比如 www.baidu.com 或者 .com.cn ，而 www.baidu.com则为子域，我们经常用子域来作为网站的域名。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E4%BB%8B%E7%BB%8D/01.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;有了网站域名，下面来看看，域名是如何解析到 ip 的，下图为域名解析过程流程图</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E4%BB%8B%E7%BB%8D/02.png?raw=true" alt=""></figure></p>
<ol>
<li><p>在浏览器中输入 www.sina.com.cn 域名，操作系统会先检查子机本地的 hosts 文件是否有这个网站映射关系，如果有，就先调用这个 IP 地址映射，完成域名解析。</p>
</li>
<li><p>如果 hosts 里没有这个域名的映射，则查找本地 DNS 解析器缓存，是否有这个网址映射关系，如果有，直接返回，完成域名解析。</p>
</li>
<li><p>如果 hosts 与本地 DNS 解析器缓存都没有相应的网址映射关系，首先会找本机设置的首选 DNS 服务器，在此我们叫它本地 DNS 服务器，此服务器收到查询时，如果要查询的域名，包含在本地配置区域资源中，则返回解析结果给客户机，完成域名解析，此解析具有权威性。</p>
</li>
<li><p>如果要查询的域名，不由本地 DNS 服务器区域解析，但该服务器已缓存了此网址映射关系，则调用这个 IP 地址映射，完成域名解析，此解析不具有权威性。</p>
</li>
<li><p>如果本地 DNS 服务器本地区域文件与缓存解析都失效，则分局本地 DNS 服务器的设置（是否设置转发器）进行查询，如果未用转发模式，本地 DNS 就把请求发至 13 台根 DNS ，根 DNS 服务器收到请求后会判断这个域名是谁来授权管理 ，并会返回一个负责该顶级域名服务器的一个 IP 。本地 DNS 服务器收到 IP 信息后，将会联系负责 域的这台服务器。这台负责 域的服务器收到请求后，如果自己无法解析，它就会找一个管理 管理域的下一级 DNS 服务器地址给本地 DNS 服务器。当本地 DNS 服务器收到这个地址后，就会找这个域服务器，重复上面的动作，进行查询，直至找到 www.sina.com.cn 主机。</p>
</li>
<li><p>如果用的是转发模式，此 DNS 服务器就会把请求转发至上一级服务器进行解析，上一级服务器如果不能解析，或找根 DNS 或把转请求转至上上级，以此循环。不管是本地 DNS 服务器用是是转发，还是根提示，最后都是把结果返回给本地 DNS 服务器，由此 DNS 服务器再返回给客户机。</p>
</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E4%BB%8B%E7%BB%8D/03.png?raw=true" alt=""></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/3. DNS安装配置/">DNS安装配置</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用 bind 来搭建 DNS 服务，首先安装 bind</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># yum install -y bind</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;备份配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># cp /etc/named.conf /etc/named.conf.bak</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;把默认配置文件清空，然后自定义配置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># &gt;/etc/named.conf</span></div><div class="line">[root@192 ~]<span class="comment"># vim /etc/named.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入如下配置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">options &#123;</div><div class="line">    directory <span class="string">"/var/named"</span>;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"."</span> IN &#123;</div><div class="line">    <span class="built_in">type</span> hint;</div><div class="line">    file <span class="string">"named.ca"</span>;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"localhost"</span> IN &#123;</div><div class="line">    <span class="built_in">type</span> master;</div><div class="line">    file <span class="string">"localhost.zone"</span>;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"0.0.127.in-addr.arpa"</span> IN &#123;</div><div class="line">    <span class="built_in">type</span> master;</div><div class="line">    file <span class="string">"named.local"</span>;</div><div class="line">&#125;;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存配置后，修改其属主</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># chown named /etc/named.conf</span></div><div class="line">[root@192 ~]<span class="comment"># cd /var/named</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;定义根域配置文件，没有 dig 命令先安装</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># yum install bind-utils</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># dig -t NS .&gt;named.ca</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后定义本地域配置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># vim localhost.zone</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">@            IN     SOA     localhost.   admin.localhost. (</div><div class="line">                                                             2017041101</div><div class="line">                                                             1H</div><div class="line">                                                             10M</div><div class="line">                                                             7D</div><div class="line">                                                             1D</div><div class="line">                                                                 )</div><div class="line">@             IN          NS           localhost.</div><div class="line">localhost.    IN          A            127.0.0.1</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;再定以泛解析配置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># vim named.local</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="variable">$TTL</span> 86400</div><div class="line">@                IN    SOA    localhost.   admin.localhost.  (</div><div class="line">                                                              2017041101</div><div class="line">                                                              1H</div><div class="line">                                                              10M</div><div class="line">                                                              7D</div><div class="line">                                                              1D</div><div class="line">                                                              )</div><div class="line">@                IN    NS             localhost.</div><div class="line">1                IN    PTR            localhost</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测配置是否有问题</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># named-checkconf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测正解析</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># named-checkzone "localhost" /var/named/localhost.zone</span></div><div class="line">/var/named/localhost.zone:2: no TTL specified; using SOA MINTTL instead</div><div class="line">zone localhost/IN: loaded serial 2017041101</div><div class="line">OK</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测反解析</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># named-checkzone "0.0.127.in-addr.arpa" /var/named/named.local</span></div><div class="line">zone 0.0.127.in-addr.arpa/IN: loaded serial 2017041101</div><div class="line">OK</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;生成 rndc.key ，如果没有这个 key ， named 是启动不了的。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># rndc-confgen -r /dev/urandom -a</span></div><div class="line">wrote key file <span class="string">"/etc/rndc.key"</span></div><div class="line">[root@192 named]<span class="comment"># chown named:named /etc/rndc.key</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动 named 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># /etc/init.d/named start</span></div><div class="line">启动 named： [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看是否有 53 端口</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># netstat -lnp | grep named</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/01.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先测试正向解析</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/02.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;接着测试反解析</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/03.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;现在只是建立了一个本地的域 localhost ，下面增加一个域名（zone）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># vim /etc/named.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;增加如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">zone <span class="string">"123.com"</span> IN &#123;</div><div class="line">    <span class="built_in">type</span> master;</div><div class="line">    file <span class="string">"123.com.zone"</span>;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"137.168.192.in-addr.arpa"</span> IN &#123;</div><div class="line">    <span class="built_in">type</span> master;</div><div class="line">    file <span class="string">"192.168.zone"</span>;</div><div class="line">&#125;;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测是否有问题</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># named-checkconf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑 zone 文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># vim /var/named/123.com.zone</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测是否出错</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># named-checkzone "123.com" /var/named/123.com.zone</span></div><div class="line">zone 123.com/IN: loaded serial 2017041101</div><div class="line">OK</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑反解析文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># vim /var/named/192.168.zone</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;写入如下内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="variable">$TTL</span> 600</div><div class="line">@          IN     SOA     ns.123.com.     root.123.com. (</div><div class="line">                                                           2017041101</div><div class="line">                                                           1H</div><div class="line">                                                           10M</div><div class="line">                                                           7D</div><div class="line">                                                           1D</div><div class="line">                                                           )</div><div class="line">@          IN     NS       ns.123.com.</div><div class="line">10         IN     PTR      ns.123.com.</div><div class="line">11         IN     PTR      mail.123.com.</div><div class="line">73         IN     PTR      www.123.com.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检测是否出错</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># named-checkzone "137.168.192.in-addr.arpa" 192.168.zone</span></div><div class="line">zone 137.168.192.in-addr.arpa/IN: loaded serial 2017041101</div><div class="line">OK</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启 named 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># /etc/init.d/named restart</span></div><div class="line">停止 named：. [确定]</div><div class="line">启动 named： [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># dig @127.0.0.1 www.123.com</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/04.png?raw=true" alt=""></figure></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># dig @127.0.0.1 -x 192.168.137.11</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/05.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;123.com 的域配置好后，要想使用它必须把系统里面的 DNS 服务器 IP 设定为这台机器的 IP ，但是这样也会带来一个问题，它只能解析 123.com 的域名，其他域名不能解析，这时候需要给它配置 DNS 转发。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># vim /etc/named.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 options{} 里面增加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">forward first;</div><div class="line">forwarders &#123;8.8.8.8;&#125;;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/06.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这两行就是用来配置转发的，该 DNS 服务器不能解析的域名会转发到 8.8.8.8 这个 DNS 服务器上去解析。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;任何服务器都有可能因为某些原因导致不能正常提供服务，所以有必要为 DNS 服务器配置一个备用的，但是这两台服务器需要保证数据的一直性，比如更改主上配置把 www.123.com 解析 IP 更改了，那么备用服务器上也得跟着自动变。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面就是配置主从，首先在从服务器上安装 bind </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@KVM ~]<span class="comment"># yum install -y bind</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后拷贝主上的配置文件到从上，这里主服务器 192.168.0.73 ，从服务器 192.168.0.74</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以下操作在主服务器上</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># yum -y install openssh-clients</span></div><div class="line">[root@192 named]<span class="comment"># scp /etc/named.conf 192.168.0.74:/etc/</span></div><div class="line">[root@192 named]<span class="comment"># scp /var/named/localhost.zone 192.168.0.74:/var/named/</span></div><div class="line">[root@192 named]<span class="comment"># scp /var/named/named.local 192.168.0.74:/var/named/</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;从服务器上，拷贝过来后，修改一下 /etc/named.conf </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@KVM ~]<span class="comment"># vim /etc/named.conf</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/07.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/08.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;从上生成 rndc.key</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@KVM ~]<span class="comment"># rndc-confgen -r /dev/urandom -a</span></div><div class="line">wrote key file <span class="string">"/etc/rndc.key"</span></div><div class="line">[root@KVM ~]<span class="comment"># chown named:named /etc/rndc.key</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;从上启动 named </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@KVM ~]<span class="comment"># /etc/init.d/named start</span></div><div class="line">启动 named： [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动成功后会在 /var/named 下生成一个 slaves 目录，这个目录下会有 192.168.zone 和 123.com.zone 这两个文件，内容是和主上的一样的。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/09.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后在从上测试是否可以解析</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@KVM ~]<span class="comment"># dig @127.0.0.1 www.123.com</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/10.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下面测试主从同步</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在主 dns 上更改文件 </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># vim /var/named/123.com.zone</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在最后一行增加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">123     IN     A     1.1.1.1</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/11.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;另外需要修改一下 第三行的那个数字串，这个是用来做标记的，只有这个数字变化了，才可以一让从自动跟着变，数字只能是变大，不能减小， 把 2017041101 改成 2017041102</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启主 named 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 named]<span class="comment"># /etc/init.d/named restart</span></div><div class="line">停止 named：. [确定]</div><div class="line">启动 named： [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;经测试发现一个问题：就是从经常会同步特别慢，这是很要命的。所有需要做一个特殊操作，在主上的 /etc/named.conf 中，123.com 的zone 中增加两行：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">notify yes;</div><div class="line">also-notify &#123;192.168.0.74;&#125;;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%20%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/12.png?raw=true" alt=""></figure></p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/11. DNS服务器(五)：使用queryperf对DNS服务器作压力测试/">DNS服务器(五)：使用queryperf对DNS服务器作压力测试</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<h2 id="一、querperf简介"><a href="#一、querperf简介" class="headerlink" title="一、querperf简介"></a>一、querperf简介</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当我们把DNS服务器配置好后，我们肯定会想测试一下DNS服务器的性能如何，上线后如果请求数够多服务器还能否响应？于是，我们可以使用软件模拟环境，对DNS服务器作评估性的测试。在bind中，有一款自带的压力测试软件，queryperf。使用这款软件可以对DNS服务器作请求测试，并且使用方法简单，我们可以使用queryperf测试多次，取一个平均值，这样就算结果不准确，也不会和实际情况相差太大。</p>
<h2 id="二、queryperf安装"><a href="#二、queryperf安装" class="headerlink" title="二、queryperf安装"></a>二、queryperf安装</h2><ol>
<li>queryperf是bind自带的测试软件，所以我们直接上官网下载bind，解压后就能找到queryperf的安装包。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">wget http://www.isc.org/downloads/file/<span class="built_in">bind</span>-9-8-7rc2/?version=tar.gz</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/01.jpeg?raw=true)</p>
<ol>
<li>不知道为什么，这个文件下载完成后的名字是这个，index.html\?version\=tar.gz，好吧我们解压吧。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar xf index.html\?version\=tar.gz</div></pre></td></tr></table></figure>
<ol>
<li>解压后，找到目录 contrib ，bind自带的第三方软件全在这个目录里面，我们要用到的queryperf也在里面。</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/02.jpeg?raw=true)</p>
<ol>
<li>进入queryperf目录，开始编译安装。可以使用 ./configure -h 查看安装帮助，不过我们默认安装就行了。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./configure</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/03.jpeg?raw=true)</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">make</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/04.jpeg?raw=true)</p>
<ol>
<li>通过上面的编译后，展开queryperf目录，在该目录下已经生成了一个queryperf的可执行文件。这个文件就是我们要用到的程序，我们把该程序移动到/usr/bin/目录下就可以使用了。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cp queryperf /usr/bin/</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/05.jpeg?raw=true)</p>
<h2 id="三、使用queryperf测试DNS服务器"><a href="#三、使用queryperf测试DNS服务器" class="headerlink" title="三、使用queryperf测试DNS服务器"></a>三、使用queryperf测试DNS服务器</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在测试之前，我们先把DNS服务器架设好。我们以域名wubinary.com为例，架设DNS服务器,dns.wubinary.com。</p>
<ol>
<li>wubinary.com区域的资源记录文件wubinary.com.zone内容如下。</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/06.jpeg?raw=true)</p>
<ol>
<li>测试DNS服务器能否正常使用。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重新启动服务：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/07.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试域名blog.wubinary.com</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/08.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS服务器工作正常，接下来可以使用queryperf作压力测试了。</p>
<ol>
<li>queryperf使用格式：</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">queryperf [-d datafile] [-s server_addr] [-p port] [-q num_queries]</div></pre></td></tr></table></figure>
<ul>
<li>-d: 后面接上一个文件，文件的内容是用户对DNS的请求，一行为一条请求，所以为了测试，我们可以在里面写上几千几万条。</li>
<li>-s: DNS服务器地址</li>
<li>-p: DNS服务器端口</li>
<li>-q: 请求多少次</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用vim命令先创建一个请求文件：vim querytest.txt</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/09.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这几条记录还远远不够，我们使用vim命令 1,$y 复制一下。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/10.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;六百多万条了，开始测试吧。</p>
<ol>
<li>性能测试。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">queryperf -d querytest.txt -s 192.168.0.6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;此时使用top命令可以看到CPU和内存的使用率。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/11.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;结果如下：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E4%BA%94" alt=""></figure>%EF%BC%9A%E4%BD%BF%E7%94%A8queryperf%E5%AF%B9DNS%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BD%9C%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/12.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试过程完成，可以多测试几次取平均值。</p>
<h2 id="四、性能测试总结"><a href="#四、性能测试总结" class="headerlink" title="四、性能测试总结"></a>四、性能测试总结</h2><ol>
<li>在作服务器的性能测试时，最好不要在服务器平台自身使用测试软件测试，最好换另外一台机器，这样CPU处理的结果会更准确。</li>
<li>测试时先预估平台会遇到的最大请求数，用这个请求数作测试，量力而为，因为如果服务器遇到大流量的DDOS，单一机器性能再好，也扛不住。</li>
<li>使用queryperf作性能测试时，最好测试多次，取平均值。</li>
<li>可以修改配置文件的部分参数测试，如，开启递归，开启查询日志等功能作测试。</li>
<li>其它开源测试工具，tcpcopy</li>
</ol>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/10. DNS服务器(四)：DNS视图及bind中rndc的使用/">DNS服务器(四)：DNS视图及bind中rndc的使用</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<h2 id="一、DNS服务器视图功能的实现"><a href="#一、DNS服务器视图功能的实现" class="headerlink" title="一、DNS服务器视图功能的实现"></a>一、DNS服务器视图功能的实现</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS服务器有一个高级的功能，能够实现不同的用户访问同一个域名，把域名解析成不同的IP地址，使用户能够访问离他最近的服务器上的数据，这就是DNS服务器的视图功能。使用DNS服务器的视图功能可以增加网站的响应速度。例如，当我们网站的数据同步在两台web服务器上时，一台是电信服务器，一台是网通服务器，那么我们肯定希望全国访问我们网站的用户在打开网站的时候，能够自动实现，电信用户访问电信服务器，网通用户访问网通服务器。配置这种情况的前提是，web服务器必须要有一个电信的IP地址和一个网通的IP地址。DNS服务器的这种解析功能通常也被称之为智能解析。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS服务器的视图通常在配置文件中是使用view实现的。把要使用某些IP地址作单独访问的zone区域，统一放在一个命名的view段落中，并且在view中定义请求的IP地址或IP地址段，把IP地址写入match-clients选项中。如果像上面说的，区分电信和网通路线的话，那么可以使用两个acl访问控制列表写上电信或网通IP地址，定义电信网通路线，把acl名字写入view段落match-clients选项中。如下所示：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">acl telecomip&#123; tele_IP; ... &#125;;</div><div class="line">acl netcomip&#123; net_IP; ... &#125;;</div><div class="line">view telecom &#123;</div><div class="line"> match-clients &#123; telecomip; &#125;;</div><div class="line"> zone <span class="string">"ZONE_NAME"</span> IN &#123;</div><div class="line"> <span class="built_in">type</span> master;</div><div class="line"> file <span class="string">"ZONE_NAME.telecom"</span>;</div><div class="line"> &#125;;</div><div class="line">&#125;;</div><div class="line">view netcom &#123;</div><div class="line"> match-clients &#123; netcomip; &#125;;</div><div class="line"> zone <span class="string">"ZONE_NAME"</span> IN &#123;</div><div class="line"> <span class="built_in">type</span> master;</div><div class="line"> file <span class="string">"ZONE_NAME.netcom"</span>;</div><div class="line"> &#125;;</div><div class="line">&#125;;</div><div class="line">view default &#123;</div><div class="line"> match-clients &#123; any; &#125;;</div><div class="line"> zone <span class="string">"ZONE_NAME"</span> IN &#123;</div><div class="line"> <span class="built_in">type</span> master;</div><div class="line"> file <span class="string">"ZONE_NAME.netcom"</span>;</div><div class="line"> &#125;;</div><div class="line">&#125;;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需要注意的是：</p>
<ul>
<li>如果使用了视图的功能，那么配置文件中的所有zone区域都要必须写在视图里面，如，配置文件里默认要配置的三个区域，根、127.0.0.1、1.0.0.127.in-addr.arpa都要写入视图。</li>
<li>在acl中定义IP地址，IP地址的写法可以是单个IP地址也可以是一个IP地址段加掩码，如：192.168.0.0/24。</li>
<li>视图是根据配置文件从上往下匹配的，所以希望优先访问的资源记录文件，区域应该尽量写前面。</li>
<li>如果定义的若干个视图的IP地址不全的话，那么可以在最后定义一个默认视图，match-clients选项中的IP地址写上any，代表如果此次访问的IP地址上面没有一个能匹配到，则在此处归类。</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;实例：虚拟两台IP地址不同的主机，实现DNS服务器视图功能。</p>
<ol>
<li>本地电脑只有一个IP地址段，故使用两个IP地址分别代表两个不同的路线。首先，我们配置一个区域wubinary.com的DNS服务器，ip地址为,192.168.0.6。打开/etc/named.rfc1912.zones文件，编辑如下：</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div></pre></td><td class="code"><pre><div class="line">acl net &#123; 192.168.0.6; &#125;;</div><div class="line">acl <span class="built_in">local</span> &#123; 192.168.0.12; &#125;;</div><div class="line">view netcom &#123;</div><div class="line">match-clients &#123; net; &#125;;</div><div class="line">zone <span class="string">"."</span> IN &#123;</div><div class="line"><span class="built_in">type</span> hint;</div><div class="line">file <span class="string">"named.ca"</span>;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"localhost.localdomain"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"named.localhost"</span>;</div><div class="line">allow-update &#123; none; &#125;;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"localhost"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"named.localhost"</span>;</div><div class="line">allow-update &#123; none; &#125;;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"named.loopback"</span>;</div><div class="line">allow-update &#123; none; &#125;;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"1.0.0.127.in-addr.arpa"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"named.loopback"</span>;</div><div class="line">allow-update &#123; none; &#125;;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"0.in-addr.arpa"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"named.empty"</span>;</div><div class="line">allow-update &#123; none; &#125;;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"wubinary.com"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"wubinary.com.net"</span>;</div><div class="line">&#125;;</div><div class="line">&#125;;</div><div class="line">view localcom &#123;</div><div class="line">match-clients &#123; <span class="built_in">local</span>; &#125;;</div><div class="line">zone <span class="string">"wubinary.com"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"wubinary.com.local"</span>;</div><div class="line">&#125;;</div><div class="line">&#125;;</div><div class="line">view default &#123;</div><div class="line">match-clients &#123; any; &#125;;</div><div class="line">zone <span class="string">"wubinary.com"</span> IN &#123;</div><div class="line"><span class="built_in">type</span> master;</div><div class="line">file <span class="string">"wubinary.com.local"</span>;</div><div class="line">&#125;;</div><div class="line">&#125;;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：我们分别定义两个acl，用于代表两个不同路线，IP地址为192.168.0.6的机器访问的资源记录文件是 wubinary.com.net文件，IP地址为192.168.0.12和其它的机器则访问wubinary.com.local这个文件的资源记录文件。</p>
<ol>
<li>分别编辑这两个文件</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑文件/var/named/wubinary.com.net</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/01.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑文件/var/named/wubinary.com.local</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/02.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这里IP地址分别改了，192.168.0.6的机器请求时对应解析的IP是192.168开头的，192.168.0.12请求时对应解析的IP是172.16开头的。配置完成后，记得修改文件所属组及文件权限。</p>
<ol>
<li>测试一下配置文件语法。</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/03.jpeg?raw=true)</p>
<ol>
<li>好的，重新载入配置文件，在分别在两台机器上测试一下吧。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重载配置文件：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/04.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.6的机器，也就是我们DNS所属的这台机器，结果如下：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/05.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;192.168.0.12的机器，结果如下：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/06.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;两台机器请求DNS服务器时域名解析达到了预期的效果，测试成功。</p>
<h2 id="二、bind中rndc的使用"><a href="#二、bind中rndc的使用" class="headerlink" title="二、bind中rndc的使用"></a>二、bind中rndc的使用</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;rndc是Remote Name Domain Controllerr的简写，它是一个远程管理bind的工具。在使用rndc管理bind前需要使用rndc生成一对密钥文件，一半保存于rndc的配置文件中，另一半保存于bind主配置文件中。rndc的配置文件为/etc/rndc.conf，在CentOS或者RHEL中，rndc的密钥保存在/etc/rndc.key文件中。rndc默认监听在953号端口，其实在bind9中rndc默认就是可以使用可，不需要配置密钥文件。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;rndc常用命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">status <span class="comment">#查看DNS状态</span></div><div class="line">reload <span class="comment">#重新加载配置文件</span></div><div class="line">reload zone_name <span class="comment">#重新加载指定区域</span></div><div class="line">reconfig <span class="comment">#重读配置文件并加载新增的区域</span></div><div class="line">querylog <span class="comment">#关闭或开启查询日志</span></div><div class="line">flush <span class="comment">#清空服务器的缓存</span></div><div class="line">flushname name <span class="comment">#清空指定名称相关的缓存</span></div><div class="line">trace  <span class="comment">#打开debug, debug有级别的概念，每执行一次提升一次级别</span></div><div class="line">trace LEVEL <span class="comment">#指定 debug 的级别, trace 0 表示关闭debug</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用rndc：</p>
<ol>
<li>生成密钥文件</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rndc-confgen &gt; /etc/rndc.conf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;或者</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rndc-confgen -r /dev/urandom &gt; /etc/rndc.conf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;生成的配置文件如下：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/07.jpeg?raw=true)</p>
<ol>
<li>复制上面配置文件中下面一块被注释的区域至/etc/named.conf文件中，并把注释关闭。</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/08.jpeg?raw=true)</p>
<ol>
<li>重新加载bind后就可以使用rndc管理bind了。</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/09.jpeg?raw=true)</p>
<ol>
<li>使用rndc重新加载bind的配置文件。</li>
</ol>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/10.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意：如果在使用rndc时，出现如上警告时，可以删除/etc/rndc.key文件，或者重命名该文件。</p>
<ol>
<li>DNS服务器的debug功能默认是关闭的，使用rndc trace可以开启该功能，执行一次该命令 debug 级别加一级，也可以在命令后面加一个数字作为参数，指定debug级别，当数字为0时，表示关闭debug功能。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;开启debug:</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/11.jpeg?raw=true)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;关闭debug:</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/DNS%E6%9C%8D%E5%8A%A1%E5%99%A8(%E5%9B%9B" alt=""></figure>%EF%BC%9ADNS%E8%A7%86%E5%9B%BE%E5%8F%8Abind%E4%B8%ADrndc%E7%9A%84%E4%BD%BF%E7%94%A8/12.jpeg?raw=true)</p>

	

	

</article>




	<article>
	
		<h1><a href="/2017/10/12/Dns、Iredmaill/1. dns、iredmail邮件服务/">DNS、iredmaill 邮件服务</a></h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/DNS/">DNS</a>
			</span>
		
	</div>

	

	
		<h2 id="DNS"><a href="#DNS" class="headerlink" title="DNS"></a>DNS</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;全称domain name server。域名服务器，用来解析域名的。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/dns%E3%80%81iredmaill%E9%82%AE%E4%BB%B6%E6%9C%8D%E5%8A%A1/01.png?raw=true" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;域名标准写法：www.qq.com.</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DNS是如何实现解析域名的：客户端先查找/etc/hosts里是否有对应域名的ip，没有的话查找dns服务器（在/etc/resolv.conf下配置的），首先查找缓存，缓存没有，找.根名称服务器DNS，根名称服务器说没有，但我知道.com，又找.com顶级名称服务器，从.com找到microsoft.com。最终找到example.microsoft.com。找的过程都是找的dns服务器。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># yum install -y bind</span></div><div class="line">[root@linux ~]<span class="comment"># vi /etc/named.conf          //以下是用到的配置信息，其它暂且不理会</span></div><div class="line">options &#123;</div><div class="line">        listen-on port 53 &#123; 127.0.0.1; &#125;;                //监听端口53，监听53端口的ip是谁</div><div class="line">        listen-on-v6 port 53 &#123; ::1; &#125;;                     //ipv6</div><div class="line">        directory       <span class="string">"/var/named"</span>;                    //子配置文件所对应的目录</div><div class="line">logging &#123;</div><div class="line">        channel default_debug &#123;</div><div class="line">                file <span class="string">"data/named.run"</span>;                    //日志。路径/var/named/data/named.run</div><div class="line">                severity dynamic;</div><div class="line">        &#125;;</div><div class="line">&#125;;</div><div class="line">zone <span class="string">"."</span> IN &#123;                                                    //.就是根域</div><div class="line">        <span class="built_in">type</span> hint;                                                //<span class="built_in">type</span>有三种，master主，slave从，hint根域的hint</div><div class="line">        file <span class="string">"named.ca"</span>;                                      //根域对应的文件。文件在/var/named/下</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/named.ca        //每一个域对应一个机器。</span></div><div class="line">[root@linux ~]<span class="comment"># cat /var/named/named.localhost</span></div><div class="line"><span class="variable">$TTL</span> 1D                                                                          //1D就是1天生存周期</div><div class="line">@       IN SOA  @ rname.invalid. (                                 //SOA指的是解析记录。如A、CNAME等</div><div class="line">                                        0       ; serial                 //序列号</div><div class="line">                                        1D      ; refresh            //从每隔一段时间刷一次和主的数据是否有更新</div><div class="line">                                        1H      ; retry               //发现和主不通了，再过多长时间去试一下。</div><div class="line">                                        1W      ; expire            //过期时间。缓存时间，一周</div><div class="line">                                        3H )    ; minimum       //和上面的TTL有关，上面没有定义，以此项为准 </div><div class="line">          NS          @</div><div class="line">          A             127.0.0.1</div><div class="line">          AAAA      ::1                                   //ipv6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;其中第二行的@符号指的是/etc/named.rfc1912.zones中定义的zone引号里面的内容。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named start</span></div><div class="line">[root@linux ~]<span class="comment"># dig @127.0.0.1 localhost</span></div><div class="line">[root@linux ~]<span class="comment"># dig @127.0.0.1 localhost.localdomain</span></div><div class="line">[root@linux ~]<span class="comment"># dig @127.0.0.1 -x 127.0.0.1     //测试反解析          //反解析</span></div></pre></td></tr></table></figure>
<h3 id="1-正向解析"><a href="#1-正向解析" class="headerlink" title="1.正向解析"></a>1.正向解析</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf                  //在内容的最后面增加以下内容</span></div><div class="line">zone <span class="string">"123.com"</span> IN &#123;</div><div class="line">        <span class="built_in">type</span> master;</div><div class="line">        file <span class="string">"123.com.zone"</span>;</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># named-checkconf                      //检测是否有错</span></div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/123.com.zone</span></div><div class="line"><span class="variable">$TTL</span> 1D</div><div class="line">@        IN SOA  @ admin.123.com. (</div><div class="line">                                        20161025       ; serial</div><div class="line">                                        1D      ; refresh</div><div class="line">                                        1H      ; retry</div><div class="line">                                        1W      ; expire</div><div class="line">                                        3H )    ; minimum</div><div class="line">           IN  NS      ns.123.com.</div><div class="line">           IN  MX  5   mail.123.com.</div><div class="line">mail    IN  A       192.168.1.20</div><div class="line">ns       IN  A       192.168.1.70                       //对外服务应写公网ip</div><div class="line">www   IN  A       11.11.11.11</div><div class="line">bbs     IN  CNAME   www</div><div class="line">[root@linux ~]<span class="comment"># named-checkzone "123.com" /var/named/123.com.zone</span></div><div class="line">zone 123.com/IN: loaded serial 20161025</div><div class="line">OK</div><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf</span></div><div class="line">options &#123;</div><div class="line">        listen-on port 53 &#123; 127.0.0.1;192.168.1.70; &#125;;</div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named restart</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.70 www.123.com</span></div></pre></td></tr></table></figure>
<h3 id="2-反向解析"><a href="#2-反向解析" class="headerlink" title="2.反向解析"></a>2.反向解析</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;想做邮件服务器，最好加下反解析。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf          //添加以下内容</span></div><div class="line">zone <span class="string">"1.168.192.in-addr.arpa"</span> IN &#123;</div><div class="line">        <span class="built_in">type</span> master;</div><div class="line">        file <span class="string">"1.168.192.zone"</span>;</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/1.168.192.zone</span></div><div class="line"><span class="variable">$TTL</span> 1D</div><div class="line">@        IN SOA  @ admin.123.com. (</div><div class="line">                                        20161025       ; serial</div><div class="line">                                        1D      ; refresh</div><div class="line">                                        1H      ; retry</div><div class="line">                                        1W      ; expire</div><div class="line">                                        3H )    ; minimum</div><div class="line">           IN  NS      ns.123.com.</div><div class="line">160     IN  PTR     ns.123.com.</div><div class="line">20       IN  PTR     mail.123.com.</div><div class="line">[root@linux ~]<span class="comment"># named-checkconf</span></div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named restart</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.70 -x 192.168.1.20</span></div></pre></td></tr></table></figure>
<h3 id="从DNS服务器"><a href="#从DNS服务器" class="headerlink" title="从DNS服务器"></a>从DNS服务器</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># yum install -y bind             </span></div><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf               //注释//这两行将会监听服务器上所有端口</span></div><div class="line">options &#123;</div><div class="line">//        listen-on port 53 &#123; 127.0.0.1;192.168.1.70; &#125;;</div><div class="line">//        listen-on-v6 port 53 &#123; ::1; &#125;;</div><div class="line">[root@linux ~]<span class="comment"># vim /etc/named.conf              //在文件下面添加以下信息</span></div><div class="line">zone <span class="string">"123.com"</span> IN &#123;</div><div class="line">        <span class="built_in">type</span> slave;</div><div class="line">        file <span class="string">"slaves/123.com.zone"</span>;</div><div class="line">     masters &#123; 192.168.11.160; &#125;;                      //注意大括号前后面有空格。</div><div class="line">&#125;;</div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named start</span></div><div class="line">[root@linux ~]<span class="comment"># ls /var/named/slave     //有没有生成这两个文件 </span></div><div class="line">11.168.192.zone   123.com.zone</div><div class="line">[root@linux ~]<span class="comment"># cat /var/named/slaves/123.com.zone         //查看和主上是否一致</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.20 www.123.com               //检测解析</span></div><div class="line">[root@linux ~]<span class="comment"># dig @192.168.1.20 -x 192.168.1.70</span></div><div class="line">[root@linux ~]<span class="comment"># vim /var/named/123.com.zone   //增加一个域名记录</span></div><div class="line">aming    IN    A          111.111.111.111</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;主上有更改，从上立马生效，需要在主配置文件中添加两条notify yes;also-notify { 192.168.1.20; };</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># named-checkconf</span></div><div class="line">[root@linux ~]<span class="comment"># /etc/init.d/named restart</span></div></pre></td></tr></table></figure>
<h2 id="iredmaill"><a href="#iredmaill" class="headerlink" title="iredmaill"></a>iredmaill</h2><h3 id="iredmail安装"><a href="#iredmail安装" class="headerlink" title="iredmail安装"></a>iredmail安装</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;iRedMail 是一个基于 Linux/BSD 系统的零成本、功能完备、成熟的邮件服务器解决方案。<a href="www.iredmail.com">官网</a></p>
<h4 id="iRedmail包含的套件："><a href="#iRedmail包含的套件：" class="headerlink" title="iRedmail包含的套件："></a>iRedmail包含的套件：</h4><ul>
<li>postfix发邮件的</li>
<li>dovecot收邮件的</li>
<li>apache网页web访问，数据存放mysql或者openldap里面。</li>
<li>policyd拒绝黑名单</li>
<li>amavisd杀毒、扫描垃圾邮件</li>
<li>roundcube在web页面访问邮箱收发邮件的套件。即webmail</li>
<li>awstat分析日志</li>
<li>fail2ban防止暴力破解</li>
<li>iRedAdmin管理邮件，账户增加、删除、修改</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;需有域名和服务器，服务器配置内存不低于1G</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先修改域名的MX记录指向自定义的比如mail.lishiming.net上 ,mail.lishiming.net需A记录指向购买的公网服务器ip上。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@linux ~]<span class="comment"># hostname mail.lishiming.net</span></div><div class="line">[root@linux ~]<span class="comment"># vim /etc/hosts</span></div><div class="line">127.0.0.1   mail.lishiming.net   localhost</div><div class="line">[root@linux ~]<span class="comment"># wget https://bitbucket.org/zhb/iredmail/downloads/iRedMail-0.9.5-1.tar.bz2</span></div><div class="line">[root@linux ~]<span class="comment"># cd iRedMail-0.9.0</span></div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># cd pkgs/</span></div><div class="line">[root@linux pkgs]<span class="comment"># vim get_all.sh           //里面的iredmail.org修改一下</span></div><div class="line">[root@linux pkgs]<span class="comment"># sed -i 's/iredmail.org/106.187.51.47/g' get_all.sh     //ip是日本的代理服务器</span></div><div class="line">[root@linux pkgs]<span class="comment"># cd ..</span></div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># sh iRedMail.sh</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将会出来类似于图片界面，yes–Next–按tab选择Apache（按空格键选项前会出来*号说明选中）–选择MySQL–设置mysql密码–设置域（填写域名）–设置管理员的密码–Next。输入y–是否启用iptables选择n–移动my.cnf选择y。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># for s in httpd iredapd amavisd clamd postfix dovecot cbpolicyd spamassassin clamd.amavisd saslauthd fail2ban; do /etc/init.d/$s restart; done</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动以上这些服务。</p>
<h3 id="iredmail使用"><a href="#iredmail使用" class="headerlink" title="iredmail使用"></a>iredmail使用</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;唯有dovecot启动是失败，错误提示ipv6的ip失败，这时需编辑配置文件。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># vim /etc/dovecot/dovecot.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;找到：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">listen = *  [::]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">listen = *</div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># /etc/init.d/dovecot restart</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这时浏览器访问：<a href="https://mail.lishiming.net/iredadmin" target="_blank" rel="external">https://mail.lishiming.net/iredadmin</a>        //提示：您的连接不是私密连接，这时点击下面的“高级”–继续访问。Add–User  增加一个邮箱用户。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;foxmail新建一个账号，输入新建的邮箱用户名和密码。</p>
<p><figure class="figure"><img src="http://note.youdao.com/yws/public/resource/f413494d6e99fd7f2fc23e25ee770484/xmlnote/73083A746F144E6E865BCFAB35CBF944/7728" alt="images"><figcaption class="figure__caption">images</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;接下来，进行发收邮件的测试。这时收件时速度有些慢，更改以下文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># vim /etc/policyd/cluebringer.conf           </span></div><div class="line">注释<span class="comment">#Greylisting               //灰名单</span></div><div class="line">[root@linux iRedMail-0.9.0]<span class="comment"># /etc/init.d/postfix restart; /etc/init.d/dovecot restart;/etc/init.d/cbpolicyd restart</span></div></pre></td></tr></table></figure>
<h3 id="iredmail增加域"><a href="#iredmail增加域" class="headerlink" title="iredmail增加域"></a>iredmail增加域</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;5d6d.com   MX   mail.lishiming.net.             //解析</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;浏览器访问：<a href="https://mail.lishiming.net/iredadmin" target="_blank" rel="external">https://mail.lishiming.net/iredadmin</a>        //Add–Domain  增加一个域。5d6d.com</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;之后Add增加一个邮箱用户名lishiming@5d6d.com</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在foxmail上右上角–账号管理–增加账号</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;测试收发邮件。</p>

	

	

</article>





	<span class="different-posts">📖 <a href="/page/41">more posts</a> 📖</span>



	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
